# ICX Switch Configuration Script with Posh-SSH # This script is designed to extract IP Addresses from switches.txt, SSH into the switch # with the provided credentials (brocade, brocade), and backup the configuration of the switches. # The output will be saved in the configs directory and the file will be named # for the switch IP Address and then exit the session. The directory must exist to save the files. # # Enter user credentials into the script $User = "brocade" $PWord = ConvertTo-SecureString -String "brocade" -AsPlainText -Force $Credential = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList $User, $PWord # Read hosts into the variable to perform on multiple hosts foreach($switchip in Get-Content .\switches.txt) { #Open the SSH session New-SSHSession -ComputerName $switchip -Credential ($Credential) -AcceptKey -Force -Verbose $SSHStream = New-SSHShellStream -Index 0 #Break to establish session sleep 10 # Disables page display and executes the show run command $SSHStream.WriteLine("skip-page-display") $SSHStream.WriteLine("show run") #Break to allow command to finish sleep 2 # Write output to a file named for the Switch IP Address Out-File -FilePath .\configs\$switchip.txt -InputObject $SSHStream.Read() sleep 2 # End SSH session Remove-SSHSession -Index 0 }